# 819 简单：最常见的单词
from collections import Counter


def mostCommonWord(paragraph: str, banned) -> str:
    newPara = []
    word = ''

    for i in range(0, len(paragraph)):
        if paragraph[i].isalpha():
            word += paragraph[i].lower()
        elif word:
            if word not in banned:
                newPara.append(word)
            word = ''
        if i == len(paragraph) - 1 and paragraph[i].isalpha():
            newPara.append(word)

    counter = Counter(newPara)
    maxm = max(counter.values())
    return next(s for s, count in counter.items() if count == maxm)


print(mostCommonWord("Bob hit a ball, the hit BALL flew far after it was hit.", 'hit'))
